const base64 = require('./base64.js').Base64;
import { API, baseURL } from './api.js';

/** 文件上传
 * 默认文件组 default
 * 缩略图 thumb
 * 课程 course
 * 用户 user
 * 课程私有文件 course_private
 * （云盘）资讯 article
 * 临时目录 tmp
 * 全局设置文件 system
 * 小组 group
 * 编辑区 block
 * 班级 classroom （圈子）
 * 
 * X-Auth-Token
 */
export function postUpload(group) {
	return API.postUpload + group;
}

/** 我校banner
 * code: jianmo:home_top_banner
 * 
 * X-Auth-Token
 */
export function getBanners(code) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getBanners + code,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				let response = result.data;
				if (response.code == 200) {
					resolve({
						code: response.code,
						list: response.data && response.data.posters
					})
				}
				else {
					resolve({
						code: response.code,
						message: response.error && response.error.message
					})
				}
			}
			else {
				resolve({
					code: result.statusCode,
					message: response.error && response.error.message
				})
			}
		})
	})
}

/** 我的直播课程
 * {
	limit: 6
 }
 * 
 * X-Auth-Token
 * Accept: application/vnd.edusoho.v2+json
 */
export function getMyLiveCourses(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getMyLiveCourses,
			data: data,
			method: 'GET'
		})
		.then((res) => {
			const result = res[1];
			if (result.statusCode == 200) {
				let data = result.data
				resolve({
					code: result.statusCode,
					list: data
				})
			}
			else {
				let data = result.data
				resolve({
					code: result.statusCode,
					message: data.error && data.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 在学课程
 * {
	offset: 0,
	limit: 10
 }
 * 
 * X-Auth-Token
 * Accept: application/vnd.edusoho.v2+json
 */
export function getMyLearning(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getMyLearning,
			data: data,
			method: 'GET'
		})
		.then((res) => {
			const result = res[1];
			if (result.statusCode == 200) {
				let data = result.data
				resolve({
					code: result.statusCode,
					list: data.data,
					total: data.paging.total,
					limit: data.paging.limit,
					offset: data.paging.offset
				})
			}
			else {
				let data = result.data
				resolve({
					code: result.statusCode,
					message: data.error && data.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 打卡
 * classRoomId
 * 
 * X-Auth-Token
 */
export function getSignIn(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getSignIn + data,
			method: 'GET'
		})
		.then((res) => {
			console.log('getSignIn: ', res);
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 通知
 * {
	offset: 0
	limit: 10
 }
 *
 * Accept: application/vnd.edusoho.v2+json
 * X-Auth-Token
 */
export function getNotifications(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getNotifications,
			data: data,
			method: 'GET'
		})
		.then((res) => {
			const result = res[1];
			if (result.statusCode == 200) {
				let data = result.data
				resolve({
					code: result.statusCode,
					list: data.data,
					total: data.paging.total,
					limit: data.paging.limit,
					offset: data.paging.offset
				})
			}
			else {
				let data = result.data
				resolve({
					code: result.statusCode,
					message: data.error && data.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 直播课任务/待完成作业
 * type: 
 * testpaper 考试任务
 * homework 作业任务 
 * exercise 练习任务   
 * live直播
 * 
 * X-Auth-Token
 */
export function getMyTask(type) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getMyTask + type,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				let response = result.data;
				resolve({
					code: response.code,
					list: response.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: response.error && response.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 教盟直播/推荐课程
 * {
	type: 课程类型 normal
				live
				liveOpen
				open
	sort: 排序字段 createdTime
				updatedTime
				recommendedSeq
				hitNum
				recommendedTime
				rating
				studentNum
	recommended: 1推荐课程
	offset: 0
	limit: 4
 }
 *
 * Accept: application/vnd.edusoho.v2+json
 */
export function getAllCourses(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getAllCourses,
			data: data,
			method: 'GET'
		})
		.then((res) => {
			const result = res[1];
			if (result.statusCode == 200) {
				let data = result.data
				resolve({
					code: result.statusCode,
					list: data.data,
					total: data.paging.total,
					limit: data.paging.limit,
					offset: data.paging.offset
				})
			}
			else {
				let data = result.data
				resolve({
					code: result.statusCode,
					message: data.error && data.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 登录
 *
 * {
	username,
	password
 }
 * Accept: application/vnd.edusoho.v2+json
 * Content-Type: application/x-www-form-urlencoded
 * Authorization
 */
export function postLogin(data) {
	let authorization = 'Basic ' + base64.encode(data.username + ':' + data.password)
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'Content-Type': 'application/x-www-form-urlencoded',
				Authorization: authorization
			},
			url: baseURL + API.postLogin,
			method: 'POST'
		})
		.then((res) => {
			const result = res[1];
			if (result.statusCode == 200) {
				let data = result.data
				resolve({
					code: result.statusCode,
					data: {
						id: data.user && data.user.id,
						uuid: data.user && data.user.uuid,
						nickname: data.user && data.user.nickname,
						gender: data.user && data.user.gender,
						role: data.user && data.user.roles,
						avatar: data.user && data.user.avatar,
						token: data.token
					} 
				})
			}
			else {
				let data = result.data
				resolve({
					code: result.statusCode,
					message: data.error && data.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 最新课程
 * {
	sort,
	offset: 0
	limit: 10
 }
 * Accept: application/vnd.edusoho.v2+json
 * X-Auth-Token
 */
export function getCourseSets(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getCourseSets,
			data: data,
			method: 'GET'
		})
		.then((res) => {
			const result = res[1];
			if (result.statusCode == 200) {
				let data = result.data
				resolve({
					code: result.statusCode,
					list: data.data,
					total: data.paging.total,
					limit: data.paging.limit,
					offset: data.paging.offset
				})
			}
			else {
				let data = result.data
				resolve({
					code: result.statusCode,
					message: data.error && data.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 课程筛选条件
 *
 * Accept
 * X-Auth-Token
 */
export function getCourseFilter() {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getCourseFilter,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					list: result.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 课程搜索
 * Accept: application/vnd.edusoho.v2+json
 * X-Auth-Token
 * 
 * {
	categoryId,
	title,
	sort,
	offset: 0,
	limit: 10
 }
 */
export function getCoursesByTitle(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getCoursesByTitle,
			data: data,
			method: 'GET'
		})
		.then((res) => {
			const result = res[1];
			if (result.statusCode == 200) {
				let data = result.data
				resolve({
					code: result.statusCode,
					list: data.data,
					total: data.paging.total,
					limit: data.paging.limit,
					offset: data.paging.offset
				})
			}
			else {
				let data = result.data
				resolve({
					code: result.statusCode,
					message: data.error && data.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 课程详情
 * id
 * 
 * Accept: application/vnd.edusoho.v2+json
 * X-Auth-Token
 */
export function getCourseDetail(id) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getCourseDetail + id,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					data: result.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 课程问题列表
 * courseId
 * {
	sort
 }
 * 
 * X-Auth-Token
 */
export function getCourseThread(courseId, data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getCourseThread + courseId + '/threads',
			data: data,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				let response = result.data;
				resolve({
					code: result.statusCode,
					list: response.resources
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: response.error && response.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 新建问题
 * X-Auth-Token
 * 
 * {
	type: question 问题 discussion话题
	targetType: lesson 为课时话题 course 为课程话题
	targetId: lesson 为课时id null 为课程id
	title
	content
 }
 */
export function postNewFaq(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postNewFaq,
			data: data,
			method: 'POST'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 回复问题
 * X-Auth-Token
 * {
	threadType
	courseId
	content
	threadId
 }
 */
export function postFaqThread(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postFaqThread,
			data: data,
			method: 'POST'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 课程目录
 * X-Auth-Token
 * {
	courseid
 }
 */
export function getCourseItems(courseid) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getCourseItems + courseid,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					list: result.data.data.courseItems
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 学习资料
 * courseSetId
 * 
 * X-Auth-Token
 */
export function getcoursefile(courseSetId) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getcoursefile + courseSetId,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				let response = result.data;
				resolve({
					code: response.code,
					list: response.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: response.error && response.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 加入学习
 * courseid
 * 
 * X-Auth-Token
 * Accept: application/vnd.edusoho.v2+json
 */
export function postCourseMember(courseid) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postCourseMember + courseid + '/Member',
			method: 'POST'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 新建笔记
 * courseId
 * {
	lessonId
	status
	content
 }
 *
 * X-Auth-Token
 */
export function postNewNote(courseId, data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postNewNote + courseId + '/notes',
			data: data,
			method: 'POST'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 查看下载学习资料
 * fileId
 */
export function getDownloadFile(fileId) {
	return baseURL + getDownloadFile + fileId;
}

/** 任务完成
 * courseId
 * taskid
 * 
 * X-Auth-Token
 */
export function getTaskProgress(courseId, taskid) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getTaskProgress + courseId + '/finishTask/' + taskid,
			method: 'GET'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 任务进度更新
 * X-Auth-Token
 * 
 * {
	courseId
	taskId
	events.watching
	lastTime
 }
 */
export function postTaskProgress(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'Content-Type': 'application/json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postTaskProgress,
			data: data,
			method: 'POST'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 获取题目（包括 考试，练习，作业）
 * X-Auth-Token
 */
export function getTaskDertail(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + getTaskDertail,
			data: data,
			method: 'GET'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 我的统计
 * X-Auth-Token
 */
export function getStatistics(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getStatistics,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				let response = result.data;
				resolve({
					code: response.code,
					data: response.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: response.error && response.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 我的班级信息
 * Accept
 * X-Auth-Token
 */
export function getMyClassInfo(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getMyClassInfo,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					data: result.data[0]
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 资料/我的云盘
 * X-Auth-Token
 * 
 * {
	type: 文件类型 video image document
	filename
	pageNum
	pageSize
 }
 */
export function getMyResources(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'Content-Type': 'application/json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getMyResources,
			data: data,
			method: 'POST'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				let response = result.data;
				resolve({
					code: response.code,
					list: response.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: response.error && response.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 报告
 * X-Auth-Token
 */
export function getMyReport() {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getMyReport,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					data: result.data.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 重置密码
 * X-Auth-Token
 * 
 * {
	newpassword
	confirmpassword
 }
 */
export function postResetPassword(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'Content-Type': 'application/json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postResetPassword,
			data: data,
			method: 'POST'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					data: result.data.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 关于我们
 * X-Auth-Token
 * 
 * {
	code: 合作洽谈:app101   客服热线：app102   申诉举报：app103
 }
 */
export function getAboutme(code) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getAboutme + code,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					data: result.data.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 获取个人信息
 * X-Auth-Token
 * Accept: application/vnd.edusoho.v2+json
 */
export function getMyInfo() {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				Accept: 'application/vnd.edusoho.v2+json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getMyInfo,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					data: result.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 班级排行榜
 * X-Auth-Token
 * 
 * {
	classroomId
	number
 }
 */
export function postClassRank(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'Content-Type': 'application/json',
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postClassRank,
			data: data,
			method: 'POST'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					list: result.data.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 圈子
 * X-Auth-Token
 * 
 * {
	classRoomId
	pageNum
	pageSize
	userId
	type
	content
	isShowPosts
 }
 */
export function postBaseList(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postBaseList,
			data: data,
			method: 'POST'
		})
		.then((res) => {
			const result = res[1];
			if (result.statusCode == 200) {
				let data = result.data
				resolve({
					code: result.statusCode,
					list: data.data,
					total: data.paging.total,
					limit: data.paging.pagesize,
					offset: data.paging.pagecount
				})
			}
			else {
				let data = result.data
				resolve({
					code: result.statusCode,
					message: data.error && data.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 我的回答
 * X-Auth-Token
 * 
 * {
	type
	content
	pageNum
	pageSize
 }
 */
export function postMyAnswer(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postMyAnswer,
			data: data,
			method: 'POST'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 我的笔记
 * X-Auth-Token
 * 
 * {
	content
	pageNum
	pageSize
 }
 */
export function postMyNote(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postMyNote,
			data: data,
			method: 'POST'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 回复帖子、问题
 * X-Auth-Token
 * 
 * {
	parentId
	content
	threadId
 }
 */
export function postBaseThread(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postBaseThread,
			data: data,
			method: 'POST'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 发圈子,求解答
 * X-Auth-Token
 * 
 * {
	classRoomId
	type
	title
	content
	pictureList
 }
 */
export function postBaseInfo(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postBaseInfo,
			data: data,
			method: 'POST'
		})
		.then(res => {
			console.log('res: ', res)
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 排行榜
 * X-Auth-Token
 * 
 * {
	classroomId
	type
	number
 }
 */
export function postFaqRank(data) {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.postFaqRank,
			data: data,
			method: 'POST'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					list: result.data.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}

/** 圈子我的统计
 * X-Auth-Token
 */
export function getBaseStat() {
	return new Promise((resolve, reject) => {
		uni.request({
			header: {
				'X-Auth-Token': uni.getStorageSync('X-Auth-Token')
			},
			url: baseURL + API.getBaseStat,
			method: 'GET'
		})
		.then(res => {
			const result = res[1];
			if (result.statusCode == 200) {
				resolve({
					code: result.statusCode,
					data: result.data.data
				})
			}
			else {
				resolve({
					code: result.statusCode,
					message: result.error && result.error.message
				})
			}
		})
		.catch((error) => {
			console.log('error')
			reject(error)
		})
	})
}
